package com.java.demo.thread;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;

/**
 * @auther zhangwj
 * @date 2020/8/17 6:13 下午
 */
public class Demo3 {

    public static void main(String[] args) throws InterruptedException {
        final int[] a = {0};
        System.out.println("开始执行");
        CyclicBarrier cyclicBarrier = new CyclicBarrier(2, () -> {
            System.out.println("1111111");
            System.out.println(a[0]);
        });
        Thread t1 = new Thread(() -> {
            try {
                Thread.sleep(5000);
                cyclicBarrier.await();
            } catch (InterruptedException | BrokenBarrierException e) {
                e.printStackTrace();
            }
        });
        t1.start();
        Thread t2 = new Thread(() -> {
            try {
                Thread.sleep(5000);
                cyclicBarrier.await();
            } catch (InterruptedException | BrokenBarrierException e) {
                e.printStackTrace();
            }
        });
        t2.start();
        System.out.println("线程开始执行");
    }

}


class joinDemo {


}